package com.myself.module.authority.controller;

import com.myself.common.define.controller.BaseManageController;
import com.myself.common.define.model.CommonResult;
import com.myself.module.authority.service.LoginManageService;
import com.myself.module.ci.authority.login.form.GenerateCodeForm;
import com.myself.module.ci.authority.login.form.LoginEmailCode;
import com.myself.module.ci.authority.login.form.LoginPassword;
import com.myself.module.ci.authority.login.form.RegisterForm;
import com.myself.module.ci.authority.login.vo.TokenVo;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录相关
 * @author 瑟瑟发抖
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/login")
public class LoginController extends BaseManageController {

    private final LoginManageService manageService;

    @PostMapping(value = "/register")
    public CommonResult<TokenVo> register(@Valid @RequestBody RegisterForm form) {
        return success(manageService.register(form));
    }

    @PostMapping(value = "/generateCode")
    public CommonResult<Boolean> generateCode(@Valid @RequestBody GenerateCodeForm form) {
        return success(manageService.generateCode(form));
    }


    @PostMapping(value = "/password")
    public CommonResult<TokenVo> loginByPassword(@Valid @RequestBody LoginPassword form) {
        return success(manageService.checkUserByPassword(form));
    }

    @PostMapping(value = "/code")
    public CommonResult<TokenVo> loginByCode(@Valid @RequestBody LoginEmailCode form) {
        return success(manageService.checkUserByEmailCode(form));
    }



}
